#ifndef __KCBP_CONNECT__
#define __KCBP_CONNECT__

//#include  <time.h>
//#include <sys/timeb.h>
#include <atomic>
#include "IUtility.h"
#include "IDataConnect.h"
#include "IPacket.h"
#include "KCBPCli.h"
#include "encrypt.h"

class CKcbpConnect: public virtual IConnect
{
INIT_CLASS_PRODUCT(CKcbpConnect)
public:
	const bool Init(const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize);
	const void UnInit() override final;
	const char * ConnectText();
	const bool SetConnectText(const char * szConnectText);
	const bool EnableConnect();
	const void DisableConnect();
	const bool Connected();
	const bool RunLbm(const char * pszLbmNo, void * ptrTask, void * ptrResult);
	const bool GetInfo(const char * pszInfoName, char * ptrInfoValue, int iInfoValueSize);
	const void CopyConnect(IConnect * ptrSouConnect);
    const bool ComparePassword(const char * szConnectText);
    const bool ReConnectFlag(const int iTime = 1);
    const bool RC();

private:
	shared_ptr< IStrFun > m_ptrStrFun;
	shared_ptr< ISysFun > m_ptrSysFun;
	//shared_ptr< IPacket > m_ptrLbmResultSet;
    shared_ptr< IKcbpLbmManager > m_ptrKcbpLbmManager;
    string m_strConnectText, m_strSysInfo;
	map<string, string> m_mpParaValue;
	tagKCBPConnectOptionEx m_stKCBPConnectOptionEx;
	char m_szKcxpUserName[CHAR_LEN_32], m_szKcxpUserPawd[CHAR_LEN_32], m_szLoginUserCode[CHAR_LEN_16], m_szLoginUserPasd[CHAR_LEN_32], m_szLoginUserRoles[CHAR_LEN_8];
	KCBPCLIHANDLE m_hKCBPHandle;
	bool m_bConnected, m_bUseUniformAuth, m_bIsLogin;
    atomic<long long> m_llConnectTime;
    
private:
	bool ConnectKcbp();
	bool LogIn();
	void SetUserRtObj();
	bool CallProgramAndCommit(const char * pszLbmNo, IPacket * ptrTask, ILbm * ptrLbm, IPacket * ptrResult);
	bool FillFirstResultSet(const char * pszLbmNo, IPacket * ptrResult, const char * pszInPara);
	bool FillSecondResultSet(const char * pszLbmNo, ILbm * ptrLbm, IPacket * ptrResult, int &refiRowCount);
	void FreeResource();
	void GetErrMsg(const char * pszLbmNo);	
};



#endif//__KCBP_CONNECT__